package com.vvv.method;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author vvv
 * @date 2023-10-16 16 56
 * discription
 */
public class ReentrantLockCondition {
    public static final ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        // 1. 获取锁
        lock.lock();
        // 2. Condition 就是休息室
        Condition condition1 = lock.newCondition();
        Condition condition2 = lock.newCondition();
        try {
            // 进入休息室1等待 == wait
            condition1.await();
        } catch (InterruptedException e) {
            // 可以被打断
            throw new RuntimeException(e);
        }
        // 在休息室1中随便唤醒一个 == notify
        condition1.signal();
        // 在休息室1中唤醒全部 == notifyAll
        condition1.signalAll();
    }
}
